from rest_framework import serializers

from .models import PreDepositLog
from django.contrib.auth import get_user_model
UserModel = get_user_model()


class GetPreDepositLogAllowSerializer(serializers.ModelSerializer):
    class Meta:
        model = PreDepositLog
        fields = ('operationType', 'operationMoney', 'user')

        def create(self, validated_data):
            pass


class UserSuperSerializer(serializers.ModelSerializer):
    class Meta:
        model = UserModel
        fields = ('name', 'id')


class PostPreDepositLogSuperSerializer(serializers.ModelSerializer):
    operationType = serializers.IntegerField(default=1)
    operationMoney = serializers.DecimalField(max_digits=19, decimal_places=2)
    user = UserSuperSerializer

    class Meta:
        model = PreDepositLog
        fields = ('operationMoney', 'user', 'operationType')

    def create(self, validated_data):
        return PreDepositLog.objects.create(**validated_data)


class GetPreDepositLogSuperSerializer(serializers.ModelSerializer):
    user = UserSuperSerializer()
    operationType = serializers.ChoiceField((
        (1, '预存款'),
        (2, '积分'),
    ))

    class Meta:
        model = PreDepositLog
        fields = ('operationMoney', 'user', 'operationType', 'createdAt')


class GetPreDepositLogDetailSerializer(serializers.Serializer):
    user_id = serializers.IntegerField()
